using System;
using System.Runtime.Serialization;
using Neovolve.Extensibility.VisualStudio.TestProfilerLink.Properties;

namespace Neovolve.Extensibility.VisualStudio.TestProfilerLink
{
    /// <summary>
    /// The <see cref="TestFrameworkConfigurationException"/>
    /// class is used to describe an exception that has occurred due to invalid configuration of a
    /// <see cref="TestFramework"/>.
    /// </summary>
    [Serializable]
    public class TestFrameworkConfigurationException : Exception
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkConfigurationException"/> class.
        /// </summary>
        public TestFrameworkConfigurationException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkConfigurationException"/> class.
        /// </summary>
        /// <param name="frameworkName">The name of the framework.</param>
        /// <param name="propertyName">Name of the property.</param>
        public TestFrameworkConfigurationException(String frameworkName, String propertyName)
        {
            FrameworkName = frameworkName;
            PropertyName = propertyName;
        }

        /// <summary>
        /// Gets or sets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        public string PropertyName
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the name of the framework.
        /// </summary>
        /// <value>The name of the framework.</value>
        public string FrameworkName
        {
            get;
            private set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkConfigurationException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        public TestFrameworkConfigurationException(String message)
            : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkConfigurationException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="inner">The inner.</param>
        public TestFrameworkConfigurationException(String message, Exception inner)
            : base(message, inner)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkConfigurationException"/> class.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
        protected TestFrameworkConfigurationException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <value></value>
        /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
        public override string Message
        {
            get
            {
                String message = base.Message;

                if (String.IsNullOrEmpty(FrameworkName) == false
                    && (String.IsNullOrEmpty(PropertyName) == false))
                {
                    String messageFormat = Resources.TestFrameworkConfigurationExceptionMessageFormat;

                    message = String.Format(messageFormat, FrameworkName, PropertyName);

                }
                return message;
            }
        }
    }
}